package com.qiche.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qiche.model.ComboMaster;
import com.qiche.model.InsurancePolicy;
import com.qiche.model.User;
import com.qiche.service.ComboMasterService;
import com.qiche.util.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by Linzw on 2018/01/24.
 */
@Service("comboMasterService")
public class ComboMasterServiceImpl extends BaseService<ComboMaster> implements ComboMasterService{

	@Override
	public PageInfo<ComboMaster> selectByPage(ComboMaster comboMaster, int page, int limit) {
		Example example = new Example(ComboMaster.class);
		Example.Criteria criteria = example.createCriteria();
		User currentUser = UserUtils.getCurrentUser();
		if(!UserUtils.checkIsAdmin(currentUser)){
			comboMaster.setMerchantId(currentUser.getMerchantId().longValue());
		}
		//条件筛选
		if (comboMaster.getMerchantId() != null && comboMaster.getMerchantId() != 0) {
			criteria.andEqualTo("merchantId", comboMaster.getMerchantId());
		}
		if (StringUtils.isNotBlank(comboMaster.getName())) {
			criteria.andLike("name", "%" + comboMaster.getName()+ "%");
		}

		// 分页查询
		PageHelper.startPage(page, limit);
		List<ComboMaster> policyList = selectByExample(example);
		return new PageInfo<>(policyList);
	}



}
